//
//  LoginViewController.m
//  BeanSproutEDU
//
//  Created by douya on 15/1/6.
//  Copyright (c) 2015年 douya. All rights reserved.
//

#import "LoginViewController.h"
#import "TableViewCell.h"
#import "MainViewController.h"

@interface LoginViewController ()

@end

@implementation LoginViewController
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"LoginView"];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"LoginView"];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationController.navigationBar.barTintColor=DOUYACOLOR;//导航条背景颜色
    self.navigationController.navigationBar.tintColor=[UIColor whiteColor];//导航条上itemBarBtn字体颜色
    
    UIScreen *mainScreen=[UIScreen mainScreen];
    SCREEN_WIDTH= mainScreen.bounds.size.width;
    SCREEN_HEGHT= mainScreen.bounds.size.height;
    self.title=@"登录";
    self.navigationController.navigationBar.titleTextAttributes=[NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
    self.loginTableView.delegate=self;
    self.loginTableView.dataSource=self;
    self.loginTableView.keyboardDismissMode=UIScrollViewKeyboardDismissModeOnDrag;//这个东西太好了，这个是拖拽tableView的时候键盘可以自动下去
    UIBarButtonItem *leftBtn=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(leftBtnClick)];
    self.navigationItem.leftBarButtonItem=leftBtn;
    
    
    //添加以下两个通知是为了在4s上打开键盘时让输入框往上一点  不然输入不了
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldBeginEditing) name:UITextFieldTextDidBeginEditingNotification object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldEndEditing) name:UITextFieldTextDidEndEditingNotification object:nil];
   

    
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"xxxxx");
    [self.view endEditing:YES];
}
-(void)textFieldBeginEditing
{
    if (SCREEN_WIDTH==320)
    {
        self.loginTableView.center=CGPointMake(SCREEN_WIDTH/2, SCREEN_HEGHT/2-100);
    }
    
}
-(void)textFieldEndEditing
{
    if (SCREEN_WIDTH==320)
    {
         self.loginTableView.center=CGPointMake(SCREEN_WIDTH/2, SCREEN_HEGHT/2);
    }
   
}
#pragma mark- UITableViewDelegate

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

-(TableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ID=@"cell1";
    static NSString *ID1=@"cell2";
    static NSString *ID2=@"cell3";
    
    TableViewCell *cell=nil;

    
    if (indexPath.row==0)//第三方登录窗口
    {
        cell=[tableView dequeueReusableCellWithIdentifier:ID];
        if (!cell)
        {
            NSArray *array=[[NSBundle mainBundle] loadNibNamed:@"TableViewCell" owner:nil options:nil];
            cell=array[0];
        }
        //将微博、QQlogo设置为圆角
        cell.cell1_weiboLogoBtn.clipsToBounds=YES;
        cell.cell1_weiboLogoBtn.layer.cornerRadius=34;
        cell.cell1_qqLogoBtn.clipsToBounds=YES;
        cell.cell1_qqLogoBtn.layer.cornerRadius=34;

    }
    else if (indexPath.row==1)//豆芽账号登录窗口
    {
        cell=[tableView dequeueReusableCellWithIdentifier:ID1];
        if (!cell)
        {
            NSArray *array=[[NSBundle mainBundle] loadNibNamed:@"TableViewCell" owner:nil options:nil];
            cell=array[1];
        }
    }
    else//注册、找回密码、登录
    {
        cell=[tableView dequeueReusableCellWithIdentifier:ID2];
        if (!cell)
        {
            NSArray *array=[[NSBundle mainBundle] loadNibNamed:@"TableViewCell" owner:nil options:nil];
            cell=array[2];
        }
        [cell.cell3_LoginBtn addTarget:self action:@selector(loginBtnClick) forControlEvents:UIControlEventTouchUpInside];
        
    }
    
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==2)
    {
        if (480.0f==SCREEN_HEGHT)//4,4s
        {
            return SCREEN_HEGHT-2*150-64;
        }
        else if (468.0f==SCREEN_HEGHT)//5,5s
        {
            return SCREEN_HEGHT-2*150-64;
        }
        else if (667.0f==SCREEN_HEGHT)//6
        {
            return SCREEN_HEGHT-2*150-64;
        }
        else//6 plus
        {
            return SCREEN_HEGHT-2*150-64;
        }

    }
    else
    {
        return 150;
    }
}

//点击登录按钮事件
-(void)loginBtnClick
{
    MainViewController *mainVC=[[MainViewController alloc] init];//创建主界面视图
//    //获取主window
//    NSArray *windowArr=[UIApplication sharedApplication].windows;
//    UIWindow *mainWindow=windowArr[0];
    //创建导航控制器 并将主界面控制器作为根控制器
    OrientationNavigationController *nav=[[OrientationNavigationController alloc] initWithRootViewController:mainVC];
    self.view.window.rootViewController=nav;
 
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
-(void)leftBtnClick
{
    [self dismissViewControllerAnimated:YES completion:nil];
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation

{
    return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
    
}

- (BOOL)shouldAutorotate

{
    return NO;
}




@end
